package com.ooono.factorytest;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;

public class FactoryReceiver extends BroadcastReceiver {

    private static final String SECRET_CODE = "android.provider.Telephony.SECRET_CODE";

    // process *#3646553#*
    private final Uri mFactoryUri = Uri.parse("android_secret_code://555");

    // process *#3646553#*
    private final Uri mAutoTestUri = Uri.parse("android_secret_code://666");

    @Override
    public void onReceive(Context context, Intent intent) {
        Uri uri = intent.getData();
        Log.d("tag_ooono", ">>-------------" + intent.getAction() + ", " + uri.equals(mFactoryUri));
        if (SECRET_CODE.equals(intent.getAction()) || "com.android.factorymode.SECRET_CODE".equals(intent.getAction())) {
            if (uri.equals(mFactoryUri)) {
                Intent mainIntent = new Intent();
                mainIntent.setClass(context, MainActivity.class);
                mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(mainIntent);
            } else if (uri.equals(mAutoTestUri)) {
                Intent autoIntent = new Intent();
                autoIntent.setClass(context, AutoTestMainActivity.class);
                autoIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startActivity(autoIntent);
            }
        }
    }

}
